package com.demo.my.Controller;

import com.demo.my.Entity.Department;
import com.demo.my.Service.DepartmentService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/DepUpdateServlet")
public class DepUpdateServlet extends HttpServlet {
    private DepartmentService departmentService=new DepartmentService();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id = req.getParameter("id");
        String departmentNumber = req.getParameter("departmentNumber");
        String name = req.getParameter("name");
        String manager = req.getParameter("manager");
        String telephone = req.getParameter("telephone");
        String address = req.getParameter("address");
        String notes = req.getParameter("notes");
        Department department = new Department(Integer.parseInt(id),Integer.parseInt(departmentNumber),name,manager,telephone,address,notes);
        try {
            departmentService.updateDepartment(department);
            req.getRequestDispatcher("DepPageServlet").forward(req,resp);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
